package com.example.demo.service.impl;

import com.example.demo.service.TestAsync;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.scheduling.annotation.Async;
@Service
@Slf4j
public class TestAsyncImpl implements TestAsync {
    private int num = 100;
    @Override
    //使用@Async，并将前面的注册的bean，填写到Async的value中
    @Async("taskExecutor")
    public void doAsync() {
        log.info("线程{}开始 num:{}",Thread.currentThread().getName(),num);
        log.info("线程{}执行代码逻辑",Thread.currentThread().getName());
        num = num -1;
        log.info("线程{}结束 num:{}",Thread.currentThread().getName(),num);
    }
}
